package Demo1;

public class OpratorComlexImp1 implements IOperator{
    public void addition(Object o1,Object o2){
        Complex c=new Complex();
        Complex c1=(Complex)o1;
        Complex c2=(Complex)o2;
        c.setImaginary(c1.getImaginary()+c2.getImaginary());
        c.setReal(c1.getReal()+c2.getReal());
        printResult(c);
    }
    public void subtraction(Object o1,Object o2){
        Complex c=new Complex();
        Complex c1=(Complex)o1;
        Complex c2=(Complex)o2;
        c.setReal(c1.getReal()-c2.getReal());
        c.setImaginary(c1.getImaginary()-c2.getImaginary());
        printResult(c);
    }


    public void printResult(Object o){
        Complex c=(Complex)o;
        System.out.println(c.getReal()+"+"+c.getImaginary()+"i");
    }
}
